<?php
class PreparationREQ
{
    //Variables qui contiendront la  preparation des requetes
	private $ReqInsert;
	private $ReqSelectAll;
	private $ReqSelectById;
    private $ReqSelectByName; 
    private $ReqTruncate;

    
    public function __construct($db)
    {
    	//variables renseignees lors de la preparation des requetes
    	$this->ReqInsert = $db->prepare("INSERT INTO user(NameUser, PasswordUser) VALUES (:nameUser, :passwordUser)");
	
        $this->ReqSelectAll = $db->prepare("SELECT nom, prenom FROM infirmiere ORDER BY nom");
		
        $this->ReqSelectById = $db->prepare("SELECT nom, prenom FROM infirmiere WHERE nom = ? ORDER BY nom");
       
 	    $this->ReqSelectByName = $db->prepare("SELECT nom, prenom FROM infirmiere WHERE nom LIKE ? ORDER BY nom");	
		
        $this->ReqTruncate = $db->prepare("TRUNCATE ecole");
	   
    }

	
	//Methodes publiques qui executeront les requetes deja preparees dans le constructeur.
	public function insert($NameUser, $PasswordUser)
    {
    	$this->ReqInsertEcole->execute(array(':nameUser' => $NameUser, ':passwordUser' => $PasswordUser));
    	return $this->ReqInsertEcole->rowCount();
    }

    public function selectAll()
    {
    	$this->ReqSelectEcole->execute();
        return $this->ReqSelectEcole->fetchAll();
    }
    
	public function selectById($nom)
    {
        $this->ReqSelectById->execute(array($nom));
        return $this->ReqSelectById ->fetch();
    }

    public function selectByName($nom)
    {
        $this->ReqSelectByName->execute(array('%'.$nom.'%'));
        return $this->ReqSelectByName->fetchAll();
    }
    
	public function truncate()
    {
        return $this->ReqTruncate->execute();
    }
	
}